package com.zxing.wx.controller;

import com.zxing.wx.service.SignatureService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/sign")
public class SignatureController {

    @Autowired
    private SignatureService signatureService;
    @RequestMapping("/check")
    public String checkSignature(@RequestParam(name="signature",required=false) String signature,
                                 @RequestParam(name="timestamp",required=false) String timestamp,
                                 @RequestParam(name="nonce",required=false) String nonce,
                                 @RequestParam(name="echostr",required=false) String echostr) {
        log.info("signature={}, timestamp={}, nonce={}, echostr={}", signature, timestamp, nonce, echostr);
        boolean result = signatureService.checkSignature(signature, timestamp, nonce);
        return result ? echostr : null;
    }
}
